<template>
  <div id="make_knowledgeGraph">
    <div v-if="roles === 'teacher'" class="one-btns">
      <div
        class="all-btn"
        :class="{ 'no-data': graphLinks && graphLinks.length === 0 }"
        @click="handleClick"
      >
        查看知识图谱
      </div>
    </div>
    <HomeChart2 />
  </div>
</template>
    
<script>
import HomeChart2 from "@/components/HomeChart2.vue";
export default {
  components: {
    HomeChart2,
  },
  name: "ZhishiIndex",
  data() {
    return {
      roles: "",
      courseId: "",
      graphLinks: [],
    };
  },
  created() {
    this.roles = JSON.parse(localStorage.getItem("userInfo")).roles[0];
    this.courseId = JSON.parse(localStorage.getItem("courseId"));
    this.getKnowledgeGraph();
  },
  methods: {
    getKnowledgeGraph() {
      this.$axios
        .get(`/tes/graph/graph-relation-course?courseId=${this.courseId}`)
        .then((res) => {
          this.graphLinks = res.data?.links || [];
        });
    },
    handleClick() {
      if (this.graphLinks.length === 0) return;
      this.$router.push("/aiTeaching/courseBuild/makeUpdateKnowledgeGraph");
    },
  },
};
</script>
  <style lang="scss" scoped>
#make_knowledgeGraph {
  width: 100%;
  background-color: #fff;
  padding: 20px 30px;
  box-sizing: border-box;
  overflow-x: hidden;
  min-height: 650px;
  .one-btns {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
  }
  .all-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    height: 40px;
    line-height: 40px;
    background: #457aff;
    border-radius: 4px;
    font-size: 14px;
    color: #fff;
    padding: 0 18px;
    cursor: pointer;
    &.no-data {
      color: #999;
      cursor: not-allowed;
      background: #f5f5f5;
      border: none;
    }
  }
}
</style>